﻿using ComponentFactory.Krypton.Toolkit;
using SRB.Tg.DrawingStandard;
using SRB.Tg.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SRB.Tg.Cad
{
    public partial class SubstructureForm : KryptonForm
    {
        public string fileName = "";
        public string saveFolder = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "OUTDWG";
        private MainForms _parent;
        public SubstructureForm()
        {
            InitializeComponent();
            textSaveFolder.Text = saveFolder;
        }
        public SubstructureForm(MainForms frm)
        {
            InitializeComponent();
            _parent = frm;
            textSaveFolder.Text = saveFolder;
        }
        private void btnSelectFIle_Click(object sender, EventArgs e)
        {
            //打开文件
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = "xlsx";
            dlg.Filter = "xlsx or csv Files|*.xlsx;*.csv";
            if (dlg.ShowDialog() == DialogResult.OK)
                fileName = dlg.FileName;
            if (fileName == null)
                return;
            textParaFile.Text = fileName;
        }

        private void btnSelectFolder_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folder = new FolderBrowserDialog();
            folder.Description = "选择文件所在文件夹目录";  //提示的文字
            if (folder.ShowDialog() == DialogResult.OK)
            {
                saveFolder = folder.SelectedPath;
            }
            if (saveFolder == null)
            {
                saveFolder = AppDomain.CurrentDomain.SetupInformation.ApplicationBase+ "OUTDWG";
            }
            textSaveFolder.Text = saveFolder;
        }

        #region 构件参数修改委托重新加载
        public delegate void Send_Confirm_To_Form_Main(string paraFile, string saveFolder, PierSubstructureType type);
        public event Send_Confirm_To_Form_Main Send_Confirm;
        public delegate void Send_ConfirmBefore_To_Form_Main();
        public event Send_ConfirmBefore_To_Form_Main Send_ConfirmBefore;
        #endregion
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            //SingleCAD.getInstance(_parent).SetPageModel();
            //Tools.ClearDatabase();          
            if (string.IsNullOrWhiteSpace(fileName))
            {
                MessageBox.Show("请选择桥墩构造参数文件！","提示");
                return;
            }
            else
            {
                Send_ConfirmBefore();             
            }
            Send_Confirm(fileName,saveFolder, PierSubstructureType.Pier);
        }

        private void pileRebar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                MessageBox.Show("请选择桥墩构造参数文件！", "提示");
                return;
            }
            else
            {
                Send_ConfirmBefore();
            }
            Send_Confirm(fileName, saveFolder, PierSubstructureType.PileRebar);
        }

        private void pileCapRebar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                MessageBox.Show("请选择桥墩构造参数文件！", "提示");
                return;
            }
            else
            {
                Send_ConfirmBefore();
            }
            Send_Confirm(fileName, saveFolder, PierSubstructureType.PileCapRebar);
        }

        private void columnRebar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                MessageBox.Show("请选择桥墩构造参数文件！", "提示");
                return;
            }
            else
            {
                Send_ConfirmBefore();
            }
            Send_Confirm(fileName, saveFolder, PierSubstructureType.PierRebar);
        }

        private void beamRebar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                MessageBox.Show("请选择桥墩构造参数文件！", "提示");
                return;
            }
            else
            {
                Send_ConfirmBefore();
            }
            Send_Confirm(fileName, saveFolder, PierSubstructureType.BeamRebar);
        }
    }
}
